home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / disk / linkVolume.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.7 KB  |  152 lines

  1. /*
  2.  *   $RCSfile: linkVolume.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:38 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "latch.h"
  52. #include "link.h"
  53. #include "bf.h"
  54. #include "volume.h"
  55. #include "bitvec.h"
  56. #include "threadstate.h"
  57. #include "disk.h"
  58. #include "lsn.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "openlog.h"
  62. #include "disk_funcs.h"
  63. #include "msg_funcs.h"
  64. #include "log_intfuncs.h"
  65. #include "disk_globals.h"
  66.  
  67.  
  68.  int
  69. linkVolume (
  70.  
  71.     register LINK        *link,
  72.     register VOLREC        *volRec 
  73. )
  74. {
  75.  
  76.     VOLINFO        *volInfo;
  77.     TRANSREC    *transRec;
  78.  
  79.     TRPRINT(TR_CL, TR_LEVEL_1, ("linking volume:%d to link:%d",
  80.             volRec->header->volid, link->id));
  81.  
  82.     /*
  83.      *    get a pointer to the first volinfo off the vol record
  84.      */
  85.     volInfo = (VOLINFO *) FIRST_LIST_ELEMENT( &(link->volList) );
  86.  
  87.     /*
  88.      *    run through the open list for this link
  89.      */
  90.     while (volInfo != NULL)    {
  91.  
  92.         /*
  93.          *    check to see if the vol is the target vol
  94.          */
  95.         if (volInfo->volRec == volRec)    {
  96.  
  97.             TRPRINT(TR_CL, TR_LEVEL_2, ("vol is open by link"));
  98.  
  99.             /*
  100.              *    just return success
  101.              */
  102.             return(esmNOERROR);
  103.         }
  104.  
  105.         /*
  106.          *    get a pointer to the next link element
  107.          */
  108.         volInfo = (VOLINFO *) NEXT_LIST_ELEMENT( &(volInfo->linkList) );
  109.     }
  110.     
  111.     /*
  112.      *    attempt to get a vol info structure
  113.      */
  114.     if ((volInfo = (VOLINFO *) listDeq( &VolInfoPool )) == NULL)    {
  115.  
  116.         SM_ERROR(TYPE_LOG, esmNOVOLINFO);
  117.         return(esmFAILURE);
  118.     }
  119.     
  120.     /*
  121.      *    fill in the fields of the link
  122.      */
  123.     volInfo->volid = volRec->header->volid;
  124.     volInfo->volRec = volRec;
  125.     volInfo->link = link;
  126.  
  127.     /*
  128.      *    hang the structure off the owner link and the vol table
  129.      */
  130.     listEnq( &(volRec->openList), &(volInfo->volList) );
  131.     listEnq( &(link->volList), &(volInfo->linkList) );
  132.  
  133.     /*
  134.      *    For each transaction on this link, add the volume to
  135.      *    the transaction's list of mounted volumes
  136.      */
  137.     transRec = (TRANSREC*) FIRST_LIST_ELEMENT(&(link->transList));
  138.     while (transRec != NULL) {
  139.         
  140.         CHECK_TRANSREC_MAGIC(transRec);
  141.         if (addTransVolRec(transRec, volRec) == NULL) {
  142.             return(esmFAILURE);
  143.         }
  144.         transRec = (TRANSREC*) NEXT_LIST_ELEMENT(&(transRec->linkList));
  145.     }
  146.  
  147.     /*
  148.      *    return success
  149.      */
  150.     return(esmNOERROR);
  151. }
  152.